<?php
class Admin_Form_RouteSearch extends TBB_Form
{
	public function init()
	{
		$options = array(
			'0' => 'Chưa chọn',
			'from_city' => 'Điểm đi',
			'to_city' => 'Điểm đến',
			'boarding_point' => 'Trạm đi',
			'dropping_point' => 'Trạm đến'
		);
		
		$sorter = $this->_createSorterElement($options);
		$filter = $this->_createFilterElement($options);
		$filterText = $this->_createFilterTextElement();
		$submitOnSearch = $this->_createSubmitButton();
		
		$this->addElements(array($sorter, $filter, $filterText, $submitOnSearch));
		$this->addDisplayGroup(array('sorter', 'filter', 'filterText', 'submit'),
							  'routeSearchGroup',
							  array('class' => 'fieldsetForm span-6')
		);
		
		// set decorators for form
		$this->setDecorators($this->_formDecorators);
		$this->setDisplayGroupDecorators($this->_displayGroupDecorators);
	}
	
	private function _createSubmitButton()
	{
		$submit = $this->createElement ( 'submit', 'submit' );
		$submit->setLabel ( 'Thực thi' );
		$submit->setDecorators($this->_submitDecorators);
		$submit->getDecorator('HtmlTag')->setOption('id', 'routeSearchButton');		
		$submit->setAttribs(array(
			'class' => 'span-4 last submitDecorator',
		));
		return $submit;
	}
	
	private function _createFilterTextElement()
	{
		$filterText = $this->createElement('text', 'filterText')
						   ->setLabel('Giá trị lọc: ')
						   ->setAttrib('size', 40);						   
		$filterText->setAttribs(array(
			'class' => 'span-4'
		));	
		$filterText->getDecorator('Label')->setOption('class', 'span-3 labelDecorator');
		$filterText->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $filterText;
	}
		
	private function _createFilterElement($options = array())
	{
		$filter = $this->createElement('select', 'filter')
					   ->setLabel('Lọc: ')
					   ->addMultiOptions($options);
		$filter->setAttribs(array(
			'class' => 'span-4'
		));
		$filter->getDecorator('Label')->setOption('class', 'span-3 labelDecorator');
		$filter->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $filter;
	}
	
	private function _createSorterElement($options = array())
	{
		$sorter = $this->createElement('select', 'sorter')
					   ->setLabel('Sắp xếp: ')
					   ->addMultiOptions($options);
		$sorter->setAttribs(array(
			'class' => 'span-4'
		));
		$sorter->getDecorator('Label')->setOption('class', 'span-3 labelDecorator');
		$sorter->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $sorter;
	}
}